<?php
//session_start();
header('Content-type:text/html;charset=utf-8');
header('Content-type: application/json');
header('Access-Control-Allow-Origin:*');

include_once './dbConfig.php';
include_once './public.php';

if ($_POST) {
    $user = $_POST['user'];
    $psw = $_POST['psw'];
    $psw = md5($psw); //md5加密方法
    $email = $_POST['email'];
    $code = $_POST['code'];
    $login_time = time() * 1000; //time是以秒为单位的，转换成毫秒
    if (isset($_POST['postType']) && $_POST['postType'] == 'getCode') {
        $weCode = $_POST['randomCode'];
        $phpCode = getCode();
        if (strtolower($weCode) != strtolower($phpCode)) {
            $msg = ['msg' => '验证码失败!', 'status' => 0];
            reponseEvent($msg);
        }
    }
    $insertSql = 'insert into lgz_users (name, password, email, login_time) values ("' . $user . '","' . $psw . '","' . $email . '","' . $login_time . '")';

    if ($link->query($insertSql)) {
        $msg = ['msg' => '注册成功！', 'status' => 1];
//        $_SESSION['loginUserName'] = $user;
    } else {
        $msg = ['msg' => '用户已注册！', 'status' => 0];
    }
    echo json_encode($msg);
}
